package xyz.ddlnt.servicemq.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import xyz.ddlnt.commonutil.constant.MqConstants;
import xyz.ddlnt.model.entity.Post;
import xyz.ddlnt.model.entity.UserInfo;
import xyz.ddlnt.servicemq.mapper.PostMapper;
import xyz.ddlnt.servicemq.service.PostService;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/25 20:37
 */
@Service
public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements PostService {
    @Resource
    private PostMapper postMapper;

    @Override
    public void collectCountPlusOne(Long postId) {
        LambdaUpdateWrapper<Post> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.setIncrBy(Post::getCollectCount, MqConstants.PLUS_ONE)
                .eq(Post::getId, postId);
        postMapper.update(updateWrapper);
    }

    @Override
    public void collectCountMinusOne(Long postId) {
        LambdaUpdateWrapper<Post> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.setDecrBy(Post::getCollectCount, MqConstants.MINUS_ONE)
                .eq(Post::getId, postId);
        postMapper.update(updateWrapper);
    }
}
